#include "expected.hpp"
#include "shared_ptr.hpp"
#include "try.h"
#include <iostream>

class Calculator {
public:
  tl::expected<int, Error> divide(int numerator, int denominator) {
    if (denominator == 0) {
      THROW("divide by zero");
    }
    return numerator / denominator;
  }

  tl::expected<int, Error> add(int lhs, int rhs) { return lhs + rhs; }

  tl::expected<void, Error> noop() { return {}; }
};

tl::expected<int, Error> bar(int in) {
  shared_ptr<Calculator> calculator = nullptr;
  return TRY(SMART_PTR_TRY_CALL(calculator, divide, 10, 5));
}

tl::expected<void, Error> foo() {
  auto tmp = TRY(bar(10));
  return {};
}


tl::expected<int, Error> xmain() {
    TRY(foo());
    return 0;
}

int main(int argc, char **argv) {
  CATCH(xmain());
  return 0;
}
